package org.nhindirect.stagent;

public class EntityPart 
{
    public enum EntityPartType
    {
        Header,
        HeaderBoundary,
        Body,
        Prologue,
        SubPart,
        Epilogue
    }	
	
    EntityPartType m_type;
    StringSegment m_sourceText; // Text from the source message string: VERBATIM. Necessary for signatures etc.
    String m_text;

    public EntityPart(EntityPartType type)
    {
        this.m_type = type;
        this.m_sourceText = StringSegment.createNull();
    }

    public EntityPart(EntityPartType type, StringSegment segment)
    {
        this.m_type = type;
        this.m_sourceText = segment;
    }

    public EntityPartType getType()
    {
    	return this.m_type;
    }

    protected void setType(EntityPartType value)
    {
        this.m_type = value;
    }

    
    public StringSegment getSourceText()
    {
        return this.m_sourceText;
    }

    protected void setSourceText(StringSegment value)
    {
        this.m_sourceText = value;
    }

    
    public String getText()
    {
        if (this.m_text == null)
        {
            this.m_text = this.m_sourceText.toString();
        }

        return this.m_text;
    }

    protected void setText(String value)
    {
    	if (value == null)
    	{
                throw new IllegalArgumentException();
        }
        this.m_sourceText = new StringSegment(value);
    }

    @Override
    public String toString()
    {
        return this.getText();
    }
    
    protected void appendText(String text)
    {
        this.m_text = this.getText() + text;
    }
    
    protected void appendSourceText(StringSegment segment)
    {
        this.m_sourceText.union(segment);
    }
}
